<?php
namespace app\internal\controller;
/*
 * Edit by shengxin
 * Click nbfs://nbhost/SystemFileSystem/Templates/Scripting/PHPClass.php to edit this template
 */

use cmf\controller\BaseController;
/**
 * Description of FileContoller
 *
 * @author PC
 */
class FileController extends BaseController{
    public function __construct(\think\App $app) {
        
        parent::__construct($app);
        if($this->request->route('sec')!='xinge'){
            $this->error('403 Forbiden');
        }
        
    }
    public function index(){
        $image_url = $this->request->server('REQUEST_URI');
//         = "/unZip/app/26060ee34ad5c0482789998be21dd4.png"; // 替换为你要下载的图片的 URL
        $image_name = basename($image_url); // 获取图片文件名
        if('/'== substr($image_url, 0,1)){
            $image_url = substr($image_url, 1);
        }
        $path = substr($image_url, 0, strlen($image_url)-strlen($image_name));
        if(!file_exists($path)){
            mkdir($path,0755,true);
        }
        $img_data = file_get_contents('http://app.3985.site/'.$image_url);
        file_put_contents($image_url, $img_data);
        header("Content-Type: image/jpeg");
        readfile($image_url);
        die();
    }
}
